home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch3 / SysMap.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-01  |  5.3 KB  |  158 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form SysMapForm 
  4.    Caption         =   "SysMap"
  5.    ClientHeight    =   3495
  6.    ClientLeft      =   1500
  7.    ClientTop       =   1260
  8.    ClientWidth     =   6270
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   3495
  12.    ScaleWidth      =   6270
  13.    Begin MSComDlg.CommonDialog dlgOpenFile 
  14.       Left            =   3240
  15.       Top             =   360
  16.       _ExtentX        =   847
  17.       _ExtentY        =   847
  18.       _Version        =   393216
  19.       CancelError     =   -1  'True
  20.    End
  21.    Begin VB.TextBox txtPositions 
  22.       BeginProperty Font 
  23.          Name            =   "Courier New"
  24.          Size            =   8.25
  25.          Charset         =   0
  26.          Weight          =   400
  27.          Underline       =   0   'False
  28.          Italic          =   0   'False
  29.          Strikethrough   =   0   'False
  30.       EndProperty
  31.       Height          =   3495
  32.       Left            =   3480
  33.       MultiLine       =   -1  'True
  34.       ScrollBars      =   2  'Vertical
  35.       TabIndex        =   1
  36.       Text            =   "SysMap.frx":0000
  37.       Top             =   0
  38.       Width           =   2775
  39.    End
  40.    Begin VB.PictureBox picCanvas 
  41.       AutoRedraw      =   -1  'True
  42.       Height          =   3495
  43.       Left            =   0
  44.       ScaleHeight     =   229
  45.       ScaleMode       =   3  'Pixel
  46.       ScaleWidth      =   221
  47.       TabIndex        =   0
  48.       Top             =   0
  49.       Width           =   3375
  50.    End
  51.    Begin VB.Menu mnuFile 
  52.       Caption         =   "&File"
  53.       Begin VB.Menu mnuFileOpen 
  54.          Caption         =   "&Open..."
  55.          Shortcut        =   ^O
  56.       End
  57.    End
  58. Attribute VB_Name = "SysMapForm"
  59. Attribute VB_GlobalNameSpace = False
  60. Attribute VB_Creatable = False
  61. Attribute VB_PredeclaredId = True
  62. Attribute VB_Exposed = False
  63. Option Explicit
  64. Private Type PALETTEENTRY
  65.     peRed As Byte
  66.     peGreen As Byte
  67.     peBlue As Byte
  68.     peFlags As Byte
  69. End Type
  70. Private Const RASTERCAPS = 38
  71. Private Const RC_PALETTE = &H100
  72. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  73. Private Declare Function GetPaletteEntries Lib "gdi32" (ByVal hPalette As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
  74. Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
  75. Private Const PALETTE_INDEX = &H1000000
  76. ' Display a list of the colors in the logical
  77. ' palette and how they map to the system palette.
  78. Private Sub ShowEntries()
  79. Dim num_entries As Long
  80. Dim palentry(0 To 255) As PALETTEENTRY
  81. Dim pixel As Byte
  82. Dim orig_color As Long
  83. Dim i As Integer
  84. Dim txt As String
  85.     If picCanvas.Picture = 0 Then
  86.         txtPositions.Text = "No picture loaded."
  87.         Exit Sub
  88.     ElseIf picCanvas.Picture.hPal = 0 Then
  89.         txtPositions.Text = "Default palette."
  90.         Exit Sub
  91.     End If
  92.     num_entries = GetPaletteEntries(picCanvas.Picture.hPal, 0, 256, palentry(0))
  93.     ' Save the color of pixel (0, 0).
  94.     orig_color = picCanvas.Point(0, 0)
  95.     txt = "Log Sys  Red Green Blue" & vbCrLf
  96.     For i = 0 To num_entries - 1
  97.         ' See to what system entry each logical
  98.         ' palette entry is mapped.
  99.         picCanvas.PSet (0, 0), i + PALETTE_INDEX
  100.         
  101.         GetBitmapBits picCanvas.Image, 1, pixel
  102.         
  103.         ' Add the information to the string.
  104.         txt = txt & _
  105.             Format$(i, "@@@") & _
  106.             Format$(pixel, "@@@@") & _
  107.             Format$(palentry(i).peRed, "@@@@@") & _
  108.             Format$(palentry(i).peGreen, "@@@@@@") & _
  109.             Format$(palentry(i).peBlue, "@@@@@") & _
  110.             vbCrLf
  111.     Next i
  112.     ' Restore pixel (0, 0) to its original color.
  113.     picCanvas.PSet (0, 0), orig_color
  114.     txtPositions.Text = txt
  115. End Sub
  116. Private Sub Form_Load()
  117.     ' Make sure the screen is using palettes.
  118.     If Not GetDeviceCaps(hdc, RASTERCAPS) And RC_PALETTE Then
  119.         MsgBox "This system is not using palettes."
  120.         End
  121.     End If
  122.     ' Start searching in the current directory.
  123.     dlgOpenFile.InitDir = App.Path
  124.     ShowEntries
  125. End Sub
  126. Private Sub Form_Resize()
  127. Dim wid As Single
  128.     txtPositions.Move ScaleWidth - txtPositions.Width, _
  129.         0, txtPositions.Width, ScaleHeight
  130.     wid = txtPositions.Left - 20
  131.     If wid < 100 Then wid = 100
  132.     picCanvas.Move 0, 0, wid, ScaleHeight
  133. End Sub
  134. Private Sub mnuFileOpen_Click()
  135. Dim fname As String
  136.     ' Allow the user to pick a file.
  137.     On Error Resume Next
  138.     dlgOpenFile.FileName = "*.BMP;*.WMF;*.DIB;*.JPG;*.GIF"
  139.     dlgOpenFile.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  140.     dlgOpenFile.ShowOpen
  141.     If Err.Number = cdlCancel Then
  142.         Exit Sub
  143.     ElseIf Err.Number <> 0 Then
  144.         Beep
  145.         MsgBox "Error selecting file.", , vbExclamation
  146.         Exit Sub
  147.     End If
  148.     On Error GoTo 0
  149.     fname = Trim$(dlgOpenFile.FileName)
  150.     Caption = "SysMap [" & fname & "]"
  151.     dlgOpenFile.InitDir = Left$(fname, Len(fname) _
  152.         - Len(dlgOpenFile.FileTitle) - 1)
  153.     ' Load the picture.
  154.     picCanvas.Picture = LoadPicture(fname)
  155.     ' Update the list of colors.
  156.     ShowEntries
  157. End Sub
  158.